angular.module('bw.controller')
    //查询预约
    .controller('appointmentCtrl', ['ENV', 'toast', '$rootScope', '$scope', '$cookieStore', '$state', 'baseService', '$stateParams', 'appointmentService', function(ENV, toast, $rootScope, $scope, $cookieStore, $state, baseService, $stateParams, appointmentService) {

        $scope.searchInfo = {
            IDCardNo: "",
            FlightDate: new Date(),
            _FlightDate: "",
            TakeOffStation: "CTU",
            ArriveStation: "",
            ArriveStationName: "到达地点",
            TripType: "ClearPort",
            isShowCity: false,
            showNoData: false,
            searchData: [],
            TakeOffStationName: '成都'
        };
        $scope.onLoad = true;
        if ($stateParams.type === 'jieji') {
            $scope.isJieji = true;
            $scope.searchInfo.ArriveStationName = "起飞地点";
            $scope.searchInfo.TripType = "EnterPort";
            $scope.searchInfo.ArriveStation = "CTU";
            $scope.searchInfo.TakeOffStation = "";
        } else {
            $scope.isSongji = true;
        }
        $scope.cityList = [];
        $scope.getTripsList = function() {
            $scope.searchInfo.showNoData = false;
            $scope.searchInfo.searchData = [];
            if (!$scope.searchInfo.IDCardNo) {
                toast.showToast("请填写身份证或者护照号", 3000);
                return false;
            }
            if (!$scope.searchInfo.ArriveStation && $scope.isSongji) {
                toast.showToast("请选择" + $scope.searchInfo.ArriveStationName, 3000);
                return false;
            }
            if (!$scope.searchInfo.TakeOffStation && $scope.isJieji) {
                toast.showToast("请选择" + $scope.searchInfo.ArriveStationName, 3000);
                return false;
            }
            appointmentService.getTripsList($scope.searchInfo, function(reseponse) {
                if (reseponse.Status == 1 && reseponse.Data) {
                    $scope.searchInfo.searchData = reseponse.Data;
                    if (reseponse.Data.length <= 0) {
                        $scope.searchInfo.showNoData = true;
                    }
                } else {
                    $scope.searchInfo.showNoData = true;
                }
            });
        }

        $scope.targetAppointmentPage = function(app) {
            baseService.setItem(app.PID, app);
            $state.go('createAppointment', { pId: app.PID, type: $stateParams.type });
        }

        $scope.dateChange = function() {
            $scope.searchInfo.FlightDate = $scope.searchInfo._FlightDate.getTime();
        }

        $scope.chooseCity = function(type) {
            $scope.searchInfo.isShowCity = true;
            $state.go("appointment.chooseCity");
        }

        $scope.$on("chooseCityLisenner", function(event, data) {
            $scope.searchInfo.isShowCity = false;
            if ($stateParams.type === 'jieji') {
                $scope.searchInfo.TakeOffStation = data.Code;
                $scope.searchInfo.TakeOffStationName = data.CName;
                $scope.searchInfo.ArriveStationName = data.CName;
            } else {
                $scope.searchInfo.ArriveStation = data.Code;
                $scope.searchInfo.ArriveStationName = data.CName;
            }
        });

    }]) //选择城市
    .controller('chooseCityCtrl', ['ENV', 'toast', '$compile', '$rootScope', '$scope', '$cookieStore', '$state', 'baseService', '$stateParams', 'appointmentService', function(ENV, toast, $compile, $rootScope, $scope, $cookieStore, $state, baseService, $stateParams, appointmentService) {
        $scope.myCity = '点击获取位置';
        var userAddress = baseService.getSession('userAddressByWX');
        if (userAddress) {
            $scope.myCity = userAddress;
        } else {
            wx.getLocation({
                type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
                success: function(res) {
                    appointmentService.getLocationByBaidu({ location: res.latitude + ',' + res.longitude }, function(reseponse) {
                        var dataStr = reseponse.Data.replace('renderReverse&&renderReverse(', '');
                        dataStr = dataStr.substring(0, dataStr.length - 1);
                        var data = JSON.parse(dataStr);
                        if (reseponse.Status == 1) {
                            baseService.addSession({ name: 'userAddressByWX', info: data.result.addressComponent.city })
                            $scope.myCity = data.result.addressComponent.city;
                        }
                    });
                }
            });
        }
        $scope.cityList = [];
        $scope.activeCity = 0; //默认国内
        var map = {
            "A": [],
            "B": [],
            "C": [],
            "D": [],
            "E": [],
            "F": [],
            "G": [],
            "H": [],
            "I": [],
            "J": [],
            "K": [],
            "L": [],
            "M": [],
            "N": [],
            "O": [],
            "P": [],
            "Q": [],
            "R": [],
            "S": [],
            "T": [],
            "U": [],
            "V": [],
            "W": [],
            "X": [],
            "Y": [],
            "Z": []
        };
        $scope.chooseCity = function(type) {
            $scope.activeCity = type;
            getCityList();
        };
        var getCityList = function() {
            $scope.cityList = [];
            for (attr in map) {
                map[attr] = [];
            }
            var show = function(reseponse) {
                angular.forEach(reseponse.Data.CityAirportList, function(city, i) {
                    map[city.ShellLogogram.charAt(0)].push(city);
                });
                for (attr in map) {
                    $scope.cityList.push({
                        word: attr,
                        list: map[attr]
                    });
                }
            }
            var list = baseService.getSession('cityList' + $scope.activeCity);
            if (list) {
                show(list);
            } else {
                appointmentService.getCityList({ type: $scope.activeCity }, function(reseponse) {
                    if (reseponse.Status == 1) {
                        baseService.addSession({ name: 'cityList' + $scope.activeCity, info: reseponse });
                        show(reseponse);
                    }
                });
            }
        };
        getCityList();
        $scope.selecteCity = function(city) {
            $scope.$emit("chooseCityLisenner", city);
        };
        $scope.$on('$destroy', function() {
            $scope.searchInfo.isShowCity = false;
        });
    }])
    .controller('addAppointmentCtrl', ['ENV', 'toast', '$rootScope', '$scope', '$cookieStore', '$state', 'baseService', '$stateParams', 'appointmentService', 'baiduService', function(ENV, toast, $rootScope, $scope, $cookieStore, $state, baseService, $stateParams, appointmentService, baiduService) {

        $scope.app = baseService.getItem($stateParams.pId);
        $scope.appointmentInfo = {
            "TID": $scope.app.TID,
            "PID": $scope.app.PID,
            "driverCode": '',
            "Address": "",
            "Phone": "",
            "AlternativePhone": "",
            "PickupLongitude": -1,
            "PickupLatitude": -1,
            "DestAddress": $scope.app.TakeOfStation,
            "DestLongitude": -1,
            "DestLatitude": -1,
            "AreaId": 11,
            "CityCode": "CTU",
            "isShowAddress": false,
            "isShowDialog": false,
            "dialogText": "",
            "mapData": [],
            "addressHolder": '请填写上车地点',
            "phoneHolder": '请填写您的联系电话',
            "alternativeHolder": '请填写备用电话',
        };
        if ($stateParams.type === 'jieji') {
            $scope.isJieji = true;
            $scope.appointmentInfo.addressHolder = "请填写下车地点";
            $scope.appointmentInfo.Address = $scope.app.TakeOfStation;
            $scope.appointmentInfo.DestAddress = '';
        } else {
            $scope.isSongji = true;
        }
        //确定预约
        $scope.sureAppointment = function() {
            $scope.appointmentInfo.dialogText = '预约成功，请在预约记录中关注您的预约动态';
            if (!$scope.appointmentInfo.Address && ($scope.appointmentInfo.PickupLongitude == -1 || $scope.appointmentInfo.PickupLatitude == -1)) {
                toast.showToast("请选择上车地点", 3000);
                return false;
            }
            if (!baseService.validatemobile($scope.appointmentInfo.Phone)) {
                toast.showToast("手机号码无效", 3000);
                return false;
            }
            appointmentService.sureAppointment($scope.appointmentInfo, function(reseponse) {
                if (reseponse.Status == 1 && reseponse.Data == true) {
                    $scope.isSuccess = true;
                } else {
                    $scope.isSuccess = false;
                    $scope.appointmentInfo.dialogText = reseponse.Message;
                }
                $scope.appointmentInfo.isShowDialog = true;
            });
        };
        $scope.sureAppointmentEnter = function() {
            $scope.appointmentInfo.dialogText = '预约成功，请在预约记录中关注您的预约动态';
            if (!$scope.appointmentInfo.driverCode) {
                toast.showToast("请输入司机编号", 3000);
                return false;
            }
            if (!$scope.appointmentInfo.DestAddress && ($scope.appointmentInfo.DestLongitude == -1 || $scope.appointmentInfo.DestLatitude == -1)) {
                toast.showToast("请选择下车地点", 3000);
                return false;
            }
            if (!baseService.validatemobile($scope.appointmentInfo.Phone)) {
                toast.showToast("手机号码无效", 3000);
                return false;
            }
            appointmentService.sureAppointmentEnter($scope.appointmentInfo, function(reseponse) {
                if (reseponse.Status == 1 && reseponse.Data == true) {
                    $scope.isSuccess = true;
                    $scope.myBlid = reseponse.Data.BLID;
                } else {
                    $scope.isSuccess = false;
                    $scope.appointmentInfo.dialogText = reseponse.Message;
                }
                $scope.appointmentInfo.isShowDialog = true;
            });
        };
        $scope.validatemobile = function(phone) {
            if(phone.length<6) return true;
            if (!baseService.validatemobile(phone)) {
                toast.showToast("手机号码无效", 2000);
                return false;
            }
        };
        //取消预约
        $scope.cancelAppoinment = function(app) {
            if ($stateParams.type === 'jieji') {
                $state.go('appointment', { type: 'jieji' });
            } else {
                $state.go('appointment');
            }
        };
        var searchBaiduMap = function() {
            var params = {
                query: $scope.isJieji ? $scope.appointmentInfo.DestAddress : $scope.appointmentInfo.Address,
                region: "成都",
                output: "json",
                ak: ENV.baiduMap.ak
            }
            var show = function(reseponse) {
                $scope.appointmentInfo.isShowAddress = true;
                $scope.appointmentInfo.mapData = [];
                angular.forEach(reseponse.Data.result, function(item, _i) {
                    if (item.location && item.location.lng && item.location.lat) {
                        $scope.appointmentInfo.mapData.push(item);
                    }
                });
            }
            var list = baseService.getSession('BaiduAddressList' + params.query);
            if (list) {
                show(list);
            } else {
                baiduService.get_BaiduSugestAddressList(params, function(reseponse) {
                    if (reseponse.Status == 1 && reseponse.Data && reseponse.Data.result) { //百度地图的成功状态是0
                        baseService.addSession({ info: reseponse, name: 'BaiduAddressList' + params.query })
                        show(reseponse);
                    }
                });
            }
        };
        //定义定时器 输入后500毫秒执行搜索
        $scope.searchTimeOut;
        $scope.searchBaiduMap = function() {
            clearTimeout($scope.searchTimeOut);
            $scope.searchTimeOut = setTimeout(searchBaiduMap, 500);
        };
        $scope.closeDialog = function() {
            $scope.appointmentInfo.isShowDialog = false;
            if ($scope.isSuccess) {
                $state.go("appointmentList"); //跳转到微信号有关的预约列表
            }
        };
        $scope.getOn = function() {
            appointmentService.sureGetOn({ blId: $scope.myBlid }, function(reseponse) {
                if (reseponse.Status == 1) {
                    $scope.appointmentInfo.isShowDialog = false;
                    if ($scope.isSuccess) {
                        $state.go("appointmentList"); //跳转到微信号有关的预约列表
                    }
                }
            });
        };

        $scope.selectAddress = function($address) {
            $scope.appointmentInfo.isShowAddress = false;
            $scope.appointmentInfo.Address = $address.name;
            $scope.appointmentInfo.PickupLongitude = $address.location.lng;
            $scope.appointmentInfo.PickupLatitude = $address.location.lat;
        };
        $scope.selectDestAddress = function($address) {
            $scope.appointmentInfo.isShowAddress = false;
            $scope.appointmentInfo.DestAddress = $address.name;
            $scope.appointmentInfo.DestLongitude = $address.location.lng;
            $scope.appointmentInfo.DestLatitude = $address.location.lat;
        };
        $scope.openScanQRCode = function() {
            wx.scanQRCode({
                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                success: function(res) {
                    $scope.appointmentInfo.driverCode = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                    $scope.$apply();
                }
            });
        };
    }]).controller('appointmentListCtrl', ['ENV', 'toast', '$rootScope', '$scope', '$cookieStore', '$state', 'baseService', '$stateParams', 'appointmentService', 'baiduService', function(ENV, toast, $rootScope, $scope, $cookieStore, $state, baseService, $stateParams, appointmentService, baiduService) {

        $scope.app = baseService.getItem($stateParams.pId);
        $scope.appointmentList = [];
        $scope.noMore = false;

        function serachList(page, callback) {
            var list = [];
            appointmentService.getOrderItems({ KeyWord: "", Type: 1, PageIndex: page, PageSize: 10 }, function(reseponse) {
                if (callback) callback();
                if (reseponse.Status == 1) {
                    if (reseponse.Data) {
                        var _list = reseponse.Data.Items;
                        angular.forEach(_list, function(app, _i) {
                            if (app.Status == "Confirmed" || app.Status == "Registered" || app.Status == "BookSuccess" || (app.TripType === 'ClearPort' && app.Status == "InHand") || (app.TripType === 'EnterPort' && app.Status == "Aboard")) {
                                app.isCancel = true;
                            } else {
                                app.isCancel = false;
                            }
                            list.push(app);
                        });
                        if (list && list.length > 0) {
                            if ($scope.appointmentList.length == 0) {
                                $scope.appointmentList = list;
                            } else {
                                angular.forEach(list, function(li, i) {
                                    $scope.appointmentList.push(li)
                                        /*angular.forEach($scope.appointmentList, function(ali, k) {
                                            if (li.BLID == ali.BLID) {
                                                ali.StatusVal = li.StatusVal;
                                            }
                                        });*/
                                });
                            }
                        }
                    }
                    if (reseponse.Data && reseponse.Data.TotalPageCount >= $scope.demo.page) {
                        $scope.demo.busy = false;
                        $scope.demo.page += 1;
                    } else {
                        if ($scope.demo.page == 1) {
                            $scope.noMessage = true
                        } else {
                            $scope.noMore = true;
                        }
                    }
                }
            });
        }

        //取消预约
        $scope.cancelApp = function(app) {
            appointmentService.getAppStatus({ "blId": app.BLID }, function(reseponse) {
                if (reseponse.Status == 1 && reseponse.Data) {
                    if (reseponse.Data.ChildStatus == "Aboard" && app.TripType === 'ClearPort') {
                        toast.showToast("您已上车，不能取消", 3000);
                    } else {
                        $state.go("cancel", { blId: app.BLID });
                    }
                } else {
                    toast.showToast("未知错误，联系工作人员", 3000);
                }
            });
        };

        //根据订单不同状态，进入到不同页面
        $scope.goOtherPage = function(app) {
            //首先获取最新的订单状态，判断当前应该进入那个页面
            if (angular.element(event.target).hasClass('cancel')) return;
            appointmentService.getAppointmentInfo({ "blId": app.BLID }, function(reseponse) {
                if (reseponse.Status == 1 && reseponse.Data) {
                    // BookState Aboard 已上车
                    // BookState Arrived 已到达
                    // BookState BookSuccess 派单成功
                    // BookState Cancel 已取消
                    // BookState Completed 已完成
                    // BookState Confirmed 派单中
                    // BookState InHand 进行中
                    // BookState Registered 预约成功

                    switch (reseponse.Data.Status) {
                        case 'InHand': //进行中
                            $state.go("ongoing", { blId: app.BLID });
                            break;
                        case 'Arrived': //已到达
                            $state.go("ongoing", { blId: app.BLID });
                            break;
                        case 'Aboard': //已上车
                            $state.go("paidan", { blId: app.BLID, stateName: reseponse.Data.StatusName });
                            break;
                        case 'Completed': //已完成
                            $state.go("paidan", { blId: app.BLID, stateName: reseponse.Data.StatusName });
                            break;
                        case 'BookSuccess': //派单成功
                            $state.go("paidan", { blId: app.BLID, stateName: reseponse.Data.StatusName });
                            break;
                        case 'Cancel': //取消
                            $state.go("cancelResult", { blId: app.BLID });
                            break;
                        case 'Registered': //预约成功
                            $state.go("paidan", { blId: app.BLID, stateName: reseponse.Data.StatusName });
                            break;
                        case 'Confirmed': //派单中
                            $state.go("paidan", { blId: app.BLID, stateName: reseponse.Data.StatusName });
                            break;
                        default:
                            console.log("出错的状态");
                            break;

                    }
                }
            });
        };
        //状态改变时
        $scope.$on("signalrInfo", function(msg) {
            //serachList();
        });
        $scope.demo = {
            busy: false,
            page: 1,
            nextPage: function() {
                if ($scope.demo.busy) return;
                $scope.demo.busy = true;
                var initId = toast.showLoading();
                serachList($scope.demo.page, function() {
                    toast.hideLoading(initId);
                });
            }
        }

    }])
    .controller('cancelCtrl', ['ENV', '$compile', '$rootScope', '$scope', '$cookieStore', '$state', 'baseService', '$stateParams', 'appointmentService', 'baiduService', 'toast', function(ENV, $compile, $rootScope, $scope, $cookieStore, $state, baseService, $stateParams, appointmentService, baiduService, toast) {
        $scope.cancelResult = []; //存储取消原因选项
        $scope.cancelInfo = {
            Notes: "",
            BLIDS: [$stateParams.blId],
            editOtherResult: false,
            AccountType: "2"
        };
        //取消预约
        $scope.selectCancelInfo = function(notes) {
            $scope.isXingc = false;
            $scope.isHangb = false;
            $scope.isTime = false;
            $scope.isOther = false;
            $scope.cancelInfo.Notes = notes;
            console.info($scope);
        };
        $scope.cancelApp = function() {
            if ($scope.cancelInfo.Notes == '') {
                toast.showToast("请选择取消原因", 3000);
                return false;
            }
            if ($scope.cancelInfo.otherNotes) {
                $scope.cancelInfo.Notes = $scope.cancelInfo.Notes + '.' + $scope.cancelInfo.otherNotes;
            }
            appointmentService.cancelAppointment($scope.cancelInfo, function(reseponse) {
                if (reseponse.Status == 1) {
                    $state.go('cancelResult', { blId: $stateParams.blId });
                } else {
                    toast.showToast(reseponse.Message, 3000);
                }
            });
        };
        baseService.setTitle('取消预约');
    }])
    .controller('appointmentInfoCtrl', ['ENV', '$compile', '$rootScope', '$scope', '$cookieStore', '$state', 'baseService', '$stateParams', 'appointmentService', 'baiduService', 'toast', function(ENV, $compile, $rootScope, $scope, $cookieStore, $state, baseService, $stateParams, appointmentService, baiduService, toast) {
        $scope.cancelResult = []; //存储取消原因选项
        $scope.appointmentInfo = [];
        $scope.cancelInfo = {
            Notes: "",
            BLIDS: [$stateParams.blId],
            editOtherResult: false,
            AccountType: "2"
        }
        $scope.isJieji = false;
        $scope.noAction = $stateParams.noAction;

        function getDataList(isSignalr) {
            appointmentService.getAppointmentInfo({ "blId": $stateParams.blId }, function(reseponse) {
                if (reseponse.Status == 1 && reseponse.Data) {
                    $scope.appointmentInfo = reseponse.Data;
                    if (reseponse.Data.TripType === 'EnterPort') {
                        $scope.isJieji = true;
                        $scope.appointmentInfo.userAddress = reseponse.Data.DestAddress;
                    } else {
                        $scope.isSongji = true;
                        $scope.appointmentInfo.userAddress = reseponse.Data.PickupAddress;
                    }
                    switch (reseponse.Data.Status) {
                        case 'Completed': //已经完成
                            $scope.appointmentInfo.titleName = "已完成";
                            $scope.appointmentInfo.appStatu = "1";
                            break;
                        case 'BookSuccess': //预约成功
                            if ($scope.isJieji) {
                                $scope.appointmentInfo.titleName = "等待上车"
                            } else {
                                $scope.appointmentInfo.titleName = "派单成功";
                            }
                            $scope.appointmentInfo.appStatu = "2";
                            break;
                        case 'Confirmed': //派单中
                            $scope.appointmentInfo.titleName = "派单中";
                            $scope.appointmentInfo.appStatu = "3";
                            break;
                        case 'Registered': //预约成功
                            $scope.appointmentInfo.titleName = "预约成功";
                            $scope.appointmentInfo.appStatu = "5";
                            break;
                        case 'Aboard': //已上车
                            $scope.appointmentInfo.titleName = "已上车";
                            $scope.appointmentInfo.appStatu = "4";
                            break;
                        case 'InHand': //进行中
                            if (isSignalr) {
                                $state.go("ongoing", { blId: reseponse.Data.BLID });
                            }
                            break;
                        default:
                            console.log("出错的状态");
                            $scope.appointmentInfo.titleName = reseponse.Data.StatusName;
                            break;

                    }
                    $scope.appointmentInfo = reseponse.Data;
                    if ($scope.appointmentInfo.titleName) {
                        baseService.setTitle($scope.appointmentInfo.titleName);
                    } else {
                        baseService.setTitle(reseponse.Data.StatusName);
                    }
                }
            });
        }
        getDataList();

        /*var dataListInterval = setInterval(function() {
            getDataList();
        }, 2000);
        $scope.$on("$destroy", function() {
            clearInterval(dataListInterval);
        });*/

        //状态改变
        $scope.$on("signalrInfo", function(msg) {
            if (msg.Data.BLID == $scope.appointmentInfo.BLID) {
                getDataList(true);
            }
        });
        //确认上车
        $scope.getOn = function() {
            appointmentService.sureGetOn({ blId: $stateParams.blId }, function(reseponse) {
                if (reseponse.Status == 1) {
                    baseService.setTitle('已上车');
                    location.reload();
                }
            });
        };
    }])
    .controller('appCancelResultCtrl', ['$scope', '$cookieStore', '$state', 'baseService', '$stateParams', 'appointmentService', function($scope, $cookieStore, $state, baseService, $stateParams, appointmentService) {
        $scope.appointmentInfo = {};
        appointmentService.getAppointmentInfo({ "blId": $stateParams.blId }, function(reseponse) {
            if (reseponse.Status == 1) {
                $scope.appointmentInfo = reseponse.Data;
            }
        });
    }])
    .controller('searchOrder', ['$scope', '$rootScope', '$cookieStore', '$state', 'baseService', 'appointmentService', 'toast', function($scope, $rootScope, $cookieStore, $state, baseService, appointmentService, toast) {
        $scope.IDCardNo = $rootScope.searchOrderKeyWord ? $rootScope.searchOrderKeyWord : '';
        $scope.appointmentList = [];
        $scope.showNoData=false;
        $scope.getTripsList = function() {
            $rootScope.searchOrderKeyWord = $scope.IDCardNo;
            $scope.appointmentList = [];
            var initId = toast.showLoading();
            appointmentService.getOrderItems({ KeyWord: $scope.IDCardNo, Type: 2, PageIndex: 1, PageSize: 100 }, function(reseponse) {
                toast.hideLoading(initId);
                if (reseponse.Status == 1 && reseponse.Data) {
                    var list = reseponse.Data.Items;
                    if (list && list.length > 0) {
                        if ($scope.appointmentList.length == 0) {
                            $scope.appointmentList = list;
                        } else {
                            angular.forEach(list, function(li, i) {
                                angular.forEach($scope.appointmentList, function(ali, k) {
                                    if (li.BLID == ali.BLID) {
                                        ali.StatusVal = li.StatusVal;
                                    }
                                });
                            });
                        }
                    }
                } else {
                    $scope.showNoData = true;
                }
            });
        };
        if ($scope.IDCardNo) {
            $scope.getTripsList();
        }

        $scope.goOtherPage = function(app) {
            //首先获取最新的订单状态，判断当前应该进入那个页面
            appointmentService.getAppointmentInfo({ "blId": app.BLID }, function(reseponse) {
                if (reseponse.Status == 1 && reseponse.Data) {
                    // BookState Aboard 已上车
                    // BookState Arrived 已到达
                    // BookState BookSuccess 派单成功
                    // BookState Cancel 已取消
                    // BookState Completed 已完成
                    // BookState Confirmed 派单中
                    // BookState InHand 进行中
                    // BookState Registered 预约成功

                    switch (reseponse.Data.Status) {
                        case 'InHand': //进行中
                            $state.go("ongoing", { blId: app.BLID, noAction: true });
                            break;
                        case 'Arrived': //已到达
                            $state.go("ongoing", { blId: app.BLID, noAction: true });
                            break;
                        case 'Aboard': //已上车
                            $state.go("paidan", { blId: app.BLID, stateName: reseponse.Data.StatusName, noAction: true });
                            break;
                        case 'Completed': //已完成
                            $state.go("paidan", { blId: app.BLID, stateName: reseponse.Data.StatusName, noAction: true });
                            break;
                        case 'BookSuccess': //派单成功
                            $state.go("paidan", { blId: app.BLID, stateName: reseponse.Data.StatusName, noAction: true });
                            break;
                        case 'Cancel': //取消
                            $state.go("cancelResult", { blId: app.BLID });
                            break;
                        case 'Registered': //预约成功
                            $state.go("paidan", { blId: app.BLID, stateName: reseponse.Data.StatusName, noAction: true });
                            break;
                        case 'Confirmed': //派单中
                            $state.go("paidan", { blId: app.BLID, stateName: reseponse.Data.StatusName, noAction: true });
                            break;
                        default:
                            console.log("出错的状态");
                            break;

                    }
                }
            });
        };
    }]);
